Navbar
- Home
- Basic UI
- Navbar
To right align your navbar links, just add a right
class to your <ul>
that contains them.
<nav>
<div class="nav-wrapper">
<a href="#" class="brand-logo">Logo</a>
<ul id="nav-mobile" class="right hide-on-med-and-down">
<li><a href="#">Sass</a></li>
<li><a href="#">Components</a></li>
<li><a href="#">JavaScript</a></li>
</ul>
</div>
</nav>
To left align your navbar links, just add a left
class to your <ul>
that contains them.
<nav>
<div class="nav-wrapper">
<a href="#" class="brand-logo right">Logo</a>
<ul id="nav-mobile" class="left hide-on-med-and-down">
<li><a href="#">Sass</a></li>
<li><a href="#">Components</a></li>
<li><a href="#">JavaScript</a></li>
</ul>
</div>
</nav>
The logo will center itself on medium and down screens, but if you want the logo to
always be centered, add the center
class to your <a
class="brand-logo">
. You will have to make sure yourself that links do not overlap if you
use this.
<nav>
<div class="nav-wrapper">
<a href="#" class="brand-logo center">Logo</a>
<ul id="nav-mobile" class="left hide-on-med-and-down">
<li><a href="#">Sass</a></li>
<li><a href="#">Components</a></li>
<li><a href="#">JavaScript</a></li>
</ul>
</div>
</nav>
Apart from the material solid colors you can also use the gradient color feature with
Navbar. Just add gradient-45deg-purple-deep-orange
gradient-shadow
class to your <nav>
tag.
<nav class="gradient-45deg-purple-deep-orange gradient-shadow">
<div class="nav-wrapper">
<a href="#" class="brand-logo center">Logo</a>
<ul id="nav-mobile" class="left hide-on-med-and-down">
<li><a href="#">Sass</a></li>
<li><a href="#">Components</a></li>
<li><a href="#">JavaScript</a></li>
</ul>
</div>
</nav>
Add active class to your li tags to denote the current page.
<nav>
<div class="nav-wrapper">
<a href="#!" class="brand-logo center">Logo</a>
<ul class="left hide-on-med-and-down">
<li><a href="#">Sass</a></li>
<li><a href="#">Components</a></li>
<li class="active"><a href="#">JavaScript</a></li>
</ul>
</div>
</nav>
To add extended components to the navbar, add the class nav-extended
to the outer
nav tag. This will allow your navbar height to be variable. Then
you can just include a tabs component inside the
nav-wrapper.
<nav class="nav-extended">
<div class="nav-wrapper">
<a href="#" class="brand-logo">Logo</a>
<a href="#" data-target="mobile-demo" class="button-collapse hide-on-med-and-up"><i class="material-icons">menu</i></a>
<ul id="nav-mobile" class="right hide-on-med-and-down">
<li><a href="#">Sass</a></li>
<li><a href="#">Components</a></li>
<li><a href="#">JavaScript</a></li>
</ul>
<ul class="sidenav" id="mobile-demo">
<li><a href="#">Sass</a></li>
<li><a href="#">Components</a></li>
<li><a href="#">JavaScript</a></li>
</ul>
</div>
<div class="nav-content">
<ul class="tabs tabs-transparent">
<li class="tab"><a href="#test1">Test 1</a></li>
<li class="tab"><a class="active" href="#test2">Test 2</a></li>
<li class="tab disabled"><a href="#test3">Disabled Tab</a></li>
<li class="tab"><a href="#test4">Test 4</a></li>
</ul>
</div>
</nav>
<div id="test1" class="col s12">Test 1</div>
<div id="test2" class="col s12">Test 2</div>
<div id="test3" class="col s12">Test 3</div>
<div id="test4" class="col s12">Test 4</div>
Fixed Navbar
To make the navbar fixed, you have to add an outer wrapping div with the class navbar-fixed
.
This will offset your other content while making your nav fixed. You can adjust the height of this outer
div to change how much offset is on your content.
<div class="navbar-fixed">
<nav>
<div class="nav-wrapper">
<a href="#!" class="brand-logo">Logo</a>
<ul class="right hide-on-med-and-down">
<li><a href="#">Sass</a></li>
<li><a href="#">Components</a></li>
</ul>
</div>
</nav>
</div>
To add a navbar dropdown menu, add the ul
dropdown structure
into the page. Then, add an element to trigger the dropdown menu. Make sure to supply the id of the
dropdown structure to the
data-target
attribute of the dropdown trigger.
Trigger dropdown menu on click
By default, the dropdown menu is activated by hovering over the dropdown trigger. To activate the
dropdown menu on click, pass { hover: false }
into the above
dropdown()
function
<!-- Dropdown Structure -->
<ul id="dropdown123" class="dropdown-content">
<li><a href="#!">one</a></li>
<li><a href="#!">two</a></li>
<li class="divider"></li>
<li><a href="#!">three</a></li>
</ul>
<nav>
<div class="nav-wrapper">
<a href="#!" class="brand-logo">Logo</a>
<ul class="right hide-on-med-and-down">
<li><a href="#">Sass</a></li>
<li><a href="#">Components</a></li>
<!-- Dropdown Trigger -->
<li><a class="dropdown-trigger" href="#!" data-target="dropdown123">Dropdown<i class="material-icons right">arrow_drop_down</i></a></li>
</ul>
</div>
</nav>
$(".dropdown-trigger").dropdown();
You can add icons into links. For icon only links you don't need any additional class. Just pop the
i
tag in and it will work.
<nav>
<div class="nav-wrapper">
<a href="#!" class="brand-logo"><i class="material-icons">cloud</i>Logo</a>
<ul class="right hide-on-med-and-down">
<li><a href="#"><i class="material-icons">search</i></a></li>
<li><a href="#"><i class="material-icons">view_module</i></a></li>
<li><a href="#"><i class="material-icons">refresh</i></a></li>
<li><a href="#"><i class="material-icons">more_vert</i></a></li>
</ul>
</div>
</nav>
For adding an icon to a text link you need to add either a left
or right
class to the icon depending on where you want the icon
to be.
<nav>
<div class="nav-wrapper">
<a href="#!" class="brand-logo">Logo</a>
<ul class="right hide-on-med-and-down">
<li><a href="#"><i class="material-icons left">search</i>Link with Left Icon</a></li>
<li><a href="#"><i class="material-icons right">view_module</i>Link with Right Icon</a></li>
</ul>
</div>
</nav>
You can add buttons into links. For buttons you don't need any additional class. Just pop the .btn
class on the a
tag.
<nav>
<div class="nav-wrapper">
<a href="#!" class="brand-logo">Logo</a>
<ul class="right hide-on-med-and-down">
<li><a class="waves-effect waves-light btn">Button</a></li>
<li><a class="waves-effect waves-light btn">Button <i class="material-icons right">cloud</i></a></li>
<li><a class="waves-effect waves-light btn-large">Large Button</a></li>
</ul>
</div>
</nav>
Add a halfway FAB to your extended navbar.
<nav class="nav-extended">
<div class="nav-wrapper">
<a href="#!" class="brand-logo">Logo</a>
<ul class="right hide-on-med-and-down">
<li><a>A link</a></li>
<li><a>A second link</a></li>
<li><a>A third link</a></li>
</ul>
</div>
<div class="nav-content">
<span class="nav-title">Title</span>
<a class="btn-floating btn-large halfway-fab waves-effect waves-light teal">
<i class="material-icons">add</i>
</a>
</div>
</nav>
You can add a search form in the navbar.
<nav>
<div class="nav-wrapper">
<form>
<div class="input-field">
<input id="search" type="search" required>
<label class="label-icon" for="search"><i class="material-icons">search</i></label>
<i class="material-icons">close</i>
</div>
</form>
</div>
</nav>
When your nav bar is resized, you will see that the links on the right turn into a hamburger icon
menu. Take a look at the example below to get this functionality. Add
the entire button-collapse
line to your nav
.
<nav>
<div class="nav-wrapper">
<a href="#!" class="brand-logo">Logo</a>
<a href="#" data-target="mobile-demo2" class="button-collapse hide-on-med-and-up sidenav-trigger"><i class="material-icons">menu</i></a>
<ul class="right hide-on-med-and-down">
<li><a href="#">Sass</a></li>
<li><a href="#">Components</a></li>
<li><a href="#">Javascript</a></li>
<li><a href="#">Mobile</a></li>
</ul>
<ul class="sidenav" id="mobile-demo2">
<li><a href="#">Sass</a></li>
<li><a href="#">Components</a></li>
<li><a href="#">Javascript</a></li>
<li><a href="#">Mobile</a></li>
</ul>
</div>
</nav>
Initialization
After including the sidenav-triggerline into your navbar, all you have to do now is place this code in
your page's $( document ).ready(function(){})
code. This example
below assumes you have not modified the classes in the above example. In the case that you have, just
change the jQuery selector in the line below to match it.
$(".sidenav").sideNav();